import { checkPhone, checkNumber, checkName } from "./rules";
import ActionTypes from "../action";
export default {
  [ActionTypes.ACCOUNT_AUTH]: {
    title: "账户",
    form: [
      {
        type: "number",
        label: "手机号",
        prop: "mobile",
        placeholder: "请输入手机号",
        rule: [
          {
            required: true,
            validator: checkPhone,
            trigger: ["blur", "change"],
          },
        ],
      },
      {
        type: "password",
        label: "密码",
        prop: "password",
        placeholder: "请输入密码",
        show(_, type) {
          return type !== "edit";
        },
        rule: {
          required: true,
          message: "密码不能为空",
          trigger: "blur",
        },
      },
      {
        type: "password",
        label: "密码",
        prop: "password",
        placeholder: "请输入密码",
        show(_, type) {
          return type === "edit";
        },
      },
      {
        type: "password",
        label: "确认密码",
        prop: "confirmPassword",
        placeholder: "请再次输入密码",
        show(data, type) {
          if (type === "view") {
            return false;
          }
          if (type === "add") {
            return true;
          }
          return data.password;
        },
        rule: {
          required: true,
          message: "不能为空",
          trigger: "blur",
        },
      },
      {
        type: "text",
        label: "姓名",
        prop: "trueName",
        placeholder: "请输入姓名",
        rule: {
          required: true,
          validator: checkName,
          trigger: "change",
        },
      },
      {
        type: "text",
        label: "描述",
        prop: "body",
        placeholder: "请输入描述",
        rule: {
          required: true,
          message: "不能为空",
          trigger: "blur",
        },
      },
      {
        type: "select",
        label: "角色权限",
        prop: "${appRoleId}1",
        check_value(value) {
          return value ? Number(value) : "";
        },
        rule: {
          required: true,
          validator: checkNumber,
          trigger: "change",
        },
        auto_dispatch: "dic/getAllRole",
        option(_, $store) {
          return $store.getters["dic/allRoleList"];
        },
      },
      {
        type: "select",
        label: "省份",
        prop: "provinceCode",
        cascader: "cityCode",
        placeholder: "请选择省份",
        option(_, $store) {
          return $store.getters["dic/provinceAll"];
        },
        auto_dispatch: "dic/getCityDic",
        rule: {
          required: true,
          message: "省份不能为空",
          trigger: "blur",
        },
      },
      {
        type: "select",
        label: "城市",
        prop: "cityCode",
        cascader: "districtCode",
        placeholder: "请选择城市",
        show(data) {
          return data.provinceCode !== 0;
        },
        option(_, $store) {
          return $store.getters["dic/city"];
        },
        dispatch: "dic/getCity",
        rule: {
          required: true,
          message: "城市不能为空",
          trigger: "blur",
        },
      },
    ],
  },
  [ActionTypes.ROLE_MANAGE]: {
    title: "角色",
    form: [
      {
        type: "text",
        label: "角色名称",
        prop: "roleName",
        placeholder: "请输入角色名称",
        rule: {
          required: true,
          message: "请输入角色名称",
          trigger: "blur",
        },
      },
      {
        type: "textarea",
        label: "描述",
        placeholder: "请输入描述",
        prop: "roleDescribe",
        edit_value(value) {
          if (value && value === "undefined") {
            return "";
          }
        },
      },
      {
        type: "checkbox",
        label: "角色权限",
        prop: "permissionIds",
        auto_dispatch: "dic/getRoleDic",
        edit_value(value) {
          return value.map((val) => {
            return {
              id: val,
            };
          });
        },
        option(_, $store) {
          return $store.getters["dic/permissionOptions"];
        },
        rule: [
          {
            required: true,
            message: "请选择至少一个展会",
            trigger: "change",
          },
        ],
      },
    ],
  },
};
